//
//  RootViewController.m
//  Test_douban
//
//  Created by lanou3g on 15/7/16.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RootViewController.h"
#import "BaseNavigationController.h"

@interface RootViewController ()

@end

@implementation RootViewController

#pragma mark  -----初始化方法（init）-----
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self setUpChildViewController];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    if ([self isViewLoaded] && self.view.window == nil) {
        self.view = nil;
    }
    // Dispose of any resources that can be recreated.
}

-(void)setUpChildViewController
{
#pragma mark -----创建4个界面的 NC ，并将其放入 tabBarController-----

    UIStoryboard *mainStryBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    BaseNavigationController *HomePageNavigationController = [mainStryBoard instantiateViewControllerWithIdentifier:@"HomePageNavigationController"];
    
    UIStoryboard *LookingStryBoard = [UIStoryboard storyboardWithName:@"Looking" bundle:nil];
    BaseNavigationController *LookingNavigationController = [LookingStryBoard instantiateViewControllerWithIdentifier:@"LookingNavigationController"];
    
    UIStoryboard *PaymentStryBoard = [UIStoryboard storyboardWithName:@"Payment" bundle:nil];
    BaseNavigationController *PaymentNavigationController = [PaymentStryBoard instantiateViewControllerWithIdentifier:@"PaymentNavigationController"];
    
    UIStoryboard *UserStryBoard = [UIStoryboard storyboardWithName:@"User" bundle:nil];
    BaseNavigationController *UserNavigationController = [UserStryBoard instantiateViewControllerWithIdentifier:@"UserNavigationController"];
    
    self.viewControllers = @[HomePageNavigationController,LookingNavigationController,PaymentNavigationController,UserNavigationController];
    
    
#pragma mark -----tabBarItem-----
    
    HomePageNavigationController.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首页" image:[UIImage imageNamed:@"bottom_tab_yopark_hlight.png"] selectedImage:nil];
    LookingNavigationController.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"找房" image:[UIImage imageNamed:@"bottom_tab_zf_hlight.png"] selectedImage:nil];
    PaymentNavigationController.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"付费" image:[UIImage imageNamed:@"fangfutong_jin.png"] selectedImage:nil];
    UserNavigationController.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的" image:[UIImage imageNamed:@"bottom_tab_mine_hlight.png"] selectedImage:nil];
//
#pragma mark -----设置所有页面的头部颜色-----
    // 设置所有页面头部颜色
//    [[UINavigationBar appearance]setBarTintColor:[UIColor blueColor]];
//    [[UINavigationBar appearance]setBackgroundImage:[UIImage imageNamed:@"bg_nav.png"] forBarMetrics:UIBarMetricsDefault];
    
#pragma mark -----选择默认控制器-----
    // 设置 tabBar 默认选择的控制器
    self.selectedIndex = 0;
}

#pragma mark 选择 tabBar 所控制的控制器，会执行的方法。（每次都执行）
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    //    NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
    //    if (3 == index) {
    //        NSLog(@"Fourth");
    //    }
    //    // 等同于以上判断
    //    tabBarController.selectedIndex = 3;
    
}

#pragma mark 控制器 tabBar 是否可以点击 （屏幕旋转式，关闭用户交互）
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    return YES;//NO;
}


@end
